package com.gdziarmaga.webshop.transaction.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gdziarmaga.webshop.transaction.model.Transaction;
import com.gdziarmaga.webshop.transaction.model.TransactionBook;
import com.gdziarmaga.webshop.transaction.model.TransactionBookDAO;
import com.gdziarmaga.webshop.transaction.model.TransactionDAO;
import com.gdziarmaga.webshop.utils.filtering.BaseFilter;

@Service("transManager")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class TransactionManagerImpl implements TransactionManager {

	@Autowired
	private TransactionDAO transactionDAO;

	@Autowired
	private TransactionBookDAO transactionBookDAO;

	@Override
	public Transaction getTransactionById(Long transactionId) {
		return transactionDAO.getById(transactionId);
	}

	@Override
	public void saveTransaction(Transaction transaction) {
		transactionDAO.saveOrUpdate(transaction);

	}

	@Override
	public void saveTransactionBook(TransactionBook transactionBook) {
		transactionBookDAO.save(transactionBook);
	}

	@Override
	public void deleteTransaction(Long transactionId) {
		transactionDAO.delete(transactionId);
	}

	@Override
	public List<Transaction> getTransactionByFilter(BaseFilter filter) {
		return transactionDAO.getAll(filter);
	}

	@Override
	public List<TransactionBook> getTransactionBookByFilter(BaseFilter filter) {
		return transactionBookDAO.getAll(filter);
	}

}
